<template>
  <div>

    <el-card style="margin-top: 10px;height: 360px">
      <div slot="header"><span class="titleStyle">{{typeName}}</span>
        <el-button v-if="typeValue==0" style="float: right; padding: 3px 0" type="text" @click="add">新增
        </el-button>
      </div>
      <el-row>
        <el-col :span="4" v-for="item in webs" :key="item.name" style="margin-left: 10px">
          <el-link :href="item.url" target="_blank" class="link-name">
            {{item.name}}
          </el-link>
        </el-col>

      </el-row>

      <div style="text-align: center;margin-top: 20px">
        <el-pagination
          small
          layout="prev, pager, next"
          :total="total"
          :page-size="pageParams.pageSize"
          :current-page="pageParams.pageNum"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>
    </el-card>


    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="网站类型" prop="type">
          <el-input v-model="form.type" disabled/>
        </el-form-item>
        <el-form-item label="网站名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入网站名称"/>
        </el-form-item>
        <el-form-item label="网站地址" prop="name">
          <el-input v-model="form.url" placeholder="请输入网站地址"> <template slot="prepend">Http://</template></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import { listByGroupName,addWebsiteType,updateWebsite } from "@/api/system/website";
export default {
  props: {
    typeName: {
      type: String,
      default: ''
    },
    typeValue: {
      type: String,
      default: 0
    },
  },
  data() {
    return {
      loading: true,
      total:0,
      pageParams: {
        pageNum: 1,
        pageSize: 40,
        groupName:"",
      },
      webs:[],
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dictLabel: [
          {required: true, message: "分类名称不能为空", trigger: "blur"}
        ]
      },
    }
  },
  computed: {
  },
  watch: {},
  mounted() {

  },
  created() {
    this.getList()
  },
  methods: {
    handleCurrentChange(currentPage) {
      this.pageParams.pageNum = currentPage
      this.getList();
    },
    add() {
      this.reset();
      this.open = true;
      this.title = "添加网址";

    },
    // 表单重置
    reset() {
      this.form = {
        type: this.typeName,
        name: undefined,
        url: undefined,
      };
      this.resetForm("form");
    },
// 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dictCode != undefined) {
            updateWebsite(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList()
            });
          } else {
            addWebsiteType(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList()
            });
          }
        }
      });
    },
    /** 查询舆情清单列表 */
    getList() {
      this.pageParams.groupName=this.typeName
      this.loading = true;
      listByGroupName(this.pageParams).then(response => {
        this.webs = response.rows;
        this.total=response.total;
        this.loading = false;
      });
    },
  }
}
</script>


<style scoped lang="scss">
  .link-name {
    margin-top: 10px;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    width: 100%;
    color: #1e1e1e
  }

  .titleStyle {
    text-align: justify;
    font-weight: bold;
    font-size: 18px;
  }

</style>
